
import { _decorator, Component, Node, AudioSource, systemEvent, SystemEvent, EventMouse, log, EventKeyboard, KeyCode } from 'cc';
import { AudioSourceNew } from './AudioSourceNew';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = Music
 * DateTime = Mon Oct 25 2021 18:15:30 GMT+0800 (中国标准时间)
 * Author = linruimin
 * FileBasename = music.ts
 * FileBasenameNoExtension = music
 * URL = db://assets/audiosource/music.ts
 * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
 *
 */

@ccclass('Audio')
export class Audio extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;

    @property(AudioSourceNew)
    audioSource: AudioSourceNew = null!;

    isloop = false;

    start() {
        // [3]
        log('music clip:' + this.audioSource.clip?.name);
    }

    clickPlay()
    {
        if (this.audioSource.playing)
            this.audioSource.stop();
        else{
            this.audioSource.playbackRate = this.audioSource.playbackRateNew;
            this.audioSource.play();
        }
    }

    clickLoop()
    {
        this.isloop = !this.isloop;
        this.audioSource.loop = this.isloop;
    }

    clickPlaybackRate()
    {
        
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
 */
